﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace DDD {
    /// <summary>
    /// OpenTKのEnumをDDDのEnumに変更する拡張メソッドを追加するクラス
    /// </summary>
    public static class OpenTKExtensions {
        /// <summary>
        /// OpenTKの<seealso cref="ActiveAttribType"/>を対応するDDDの<seealso cref="ShaderVariableType"/>に変換します
        /// </summary>
        /// <remarks>
        /// Double型には対応していません。未定義の変数型はすべてUnknownになります。
        /// </remarks>
        /// <param name="type">OpenTKのActiveAttribType型</param>
        /// <returns>DDDの型</returns>
        public static ShaderVariableType ToDDD (this OpenTK.Graphics.OpenGL.ActiveAttribType type) {
            switch (type) {
                case ActiveAttribType.Float: return ShaderVariableType.Float;
                case ActiveAttribType.FloatVec2: return ShaderVariableType.Vec2;
                case ActiveAttribType.FloatVec3: return ShaderVariableType.Vec3;
                case ActiveAttribType.FloatVec4: return ShaderVariableType.Vec4;
                case ActiveAttribType.Int: return ShaderVariableType.Int;
                case ActiveAttribType.IntVec2: return ShaderVariableType.IVec2;
                case ActiveAttribType.IntVec3: return ShaderVariableType.IVec3;
                case ActiveAttribType.IntVec4: return ShaderVariableType.IVec4;
                case ActiveAttribType.UnsignedInt: return ShaderVariableType.UInt;
                case ActiveAttribType.UnsignedIntVec2: return ShaderVariableType.UIVec2;
                case ActiveAttribType.UnsignedIntVec3: return ShaderVariableType.UIVec3;
                case ActiveAttribType.UnsignedIntVec4: return ShaderVariableType.UIVec4;
                case ActiveAttribType.FloatMat2: return ShaderVariableType.Mat2x2;
                case ActiveAttribType.FloatMat3: return ShaderVariableType.Mat3x3;
                case ActiveAttribType.FloatMat4: return ShaderVariableType.Mat4x4;
                default: return ShaderVariableType.Unknown;
            }
        }

        /// <summary>
        /// OpenTKの<seealso cref="ActiveUniformType"/>を対応するDDDの<seealso cref="ShaderVariableType"/>に変換します
        /// </summary>
        /// <remarks>
        /// Double系の型はすべて未対応です。Sampler2D,2DShadow,Cube以外のサンプラーもすべて未対応です。
        /// 3x4を除く正方形でない行列はすべて未対応です。
        /// 未対応の型はすべてUnknown型になります。
        /// </remarks>
        /// <param name="type">OpenTKのActiveUniformType型</param>
        /// <returns></returns>
        public static ShaderVariableType ToDDD (this OpenTK.Graphics.OpenGL.ActiveUniformType type) {
            switch (type) {
                case ActiveUniformType.Float: return ShaderVariableType.Float;
                case ActiveUniformType.FloatVec2: return ShaderVariableType.Vec2;
                case ActiveUniformType.FloatVec3: return ShaderVariableType.Vec3;
                case ActiveUniformType.FloatVec4: return ShaderVariableType.Vec4;
                case ActiveUniformType.Int: return ShaderVariableType.Int;
                case ActiveUniformType.IntVec2: return ShaderVariableType.IVec2;
                case ActiveUniformType.IntVec3: return ShaderVariableType.IVec3;
                case ActiveUniformType.IntVec4: return ShaderVariableType.IVec4;
                case ActiveUniformType.UnsignedInt: return ShaderVariableType.UInt;
                case ActiveUniformType.UnsignedIntVec2: return ShaderVariableType.UIVec2;
                case ActiveUniformType.UnsignedIntVec3: return ShaderVariableType.UIVec3;
                case ActiveUniformType.UnsignedIntVec4: return ShaderVariableType.UIVec4;
                case ActiveUniformType.Bool: return ShaderVariableType.Bool;
                case ActiveUniformType.BoolVec2: return ShaderVariableType.BVec2;
                case ActiveUniformType.BoolVec3: return ShaderVariableType.BVec3;
                case ActiveUniformType.BoolVec4: return ShaderVariableType.BVec4;
                case ActiveUniformType.FloatMat2: return ShaderVariableType.Mat2x2;
                case ActiveUniformType.FloatMat3: return ShaderVariableType.Mat3x3;
                case ActiveUniformType.FloatMat3x4: return ShaderVariableType.Mat3x4;
                case ActiveUniformType.FloatMat4: return ShaderVariableType.Mat4x4;
                case ActiveUniformType.Sampler2D: return ShaderVariableType.Sampler2D;
                case ActiveUniformType.SamplerCube: return ShaderVariableType.SamplerCube;
                case ActiveUniformType.Sampler2DShadow: return ShaderVariableType.Sampler2DShadow;
                default: return ShaderVariableType.Unknown;
            }
        }


    }




}
